from typing import Optional, List, Union, Any
from pydantic import BaseModel, Field

from app.schemas.base import BaseEntity, PageQuery


# 部门相关
class DeptQuery(PageQuery):
    """部门查询参数"""
    deptName: Optional[str] = None
    status: Optional[str] = None


class DeptVO(BaseEntity):
    """部门视图对象 - 匹配RuoYi sys_dept表结构"""
    deptId: int
    tenantId: str
    parentId: int
    ancestors: str
    deptName: str
    deptCategory: Optional[str] = None
    orderNum: int
    leader: Optional[int] = None  # 负责人（用户ID）
    phone: Optional[str] = None
    email: Optional[str] = None
    status: str
    delFlag: str
    parentName: Optional[str] = None
    children: List["DeptVO"] = []


class DeptForm(BaseModel):
    """部门表单 - 匹配RuoYi sys_dept表结构"""
    deptId: Optional[int] = None
    parentId: int = 0
    deptName: str
    deptCategory: Optional[str] = None
    orderNum: int = 0
    leader: Optional[int] = None
    phone: Optional[str] = None
    email: Optional[str] = None
    status: str = "0"


class DeptTreeVO(BaseModel):
    """部门树结构"""
    id: int
    label: str
    children: List["DeptTreeVO"] = []


# 配置管理
class ConfigQuery(PageQuery):
    """配置查询参数"""
    configName: Optional[str] = None
    configKey: Optional[str] = None
    configType: Optional[str] = None


class ConfigVO(BaseEntity):
    """配置视图对象 - 匹配RuoYi sys_config表结构"""
    configId: int
    tenantId: str
    configName: str
    configKey: str
    configValue: str
    configType: str


class ConfigForm(BaseModel):
    """配置表单 - 匹配RuoYi sys_config表结构"""
    configId: Optional[int] = None
    configName: str
    configKey: str
    configValue: str
    configType: str = 'N'
    remark: Optional[str] = None


# 字典管理
class DictTypeQuery(PageQuery):
    """字典类型查询参数"""
    dictName: Optional[str] = None
    dictType: Optional[str] = None


class DictTypeVO(BaseEntity):
    """字典类型视图对象 - 匹配RuoYi sys_dict_type表结构"""
    dictId: int
    tenantId: str
    dictName: str
    dictType: str


class DictTypeForm(BaseModel):
    """字典类型表单 - 匹配RuoYi sys_dict_type表结构"""
    dictId: Optional[int] = None
    dictName: str
    dictType: str
    remark: Optional[str] = None


class DictDataQuery(PageQuery):
    """字典数据查询参数"""
    dictType: Optional[str] = None
    dictLabel: Optional[str] = None


class DictDataVO(BaseEntity):
    """字典数据视图对象 - 匹配RuoYi sys_dict_data表结构"""
    dictCode: int
    tenantId: str
    dictSort: int
    dictLabel: str
    dictValue: str
    dictType: str
    cssClass: Optional[str] = None
    listClass: Optional[str] = None
    isDefault: str


class DictDataForm(BaseModel):
    """字典数据表单 - 匹配RuoYi sys_dict_data表结构"""
    dictCode: Optional[int] = None
    dictSort: int = 0
    dictLabel: str
    dictValue: str
    dictType: str
    cssClass: Optional[str] = None
    listClass: Optional[str] = None
    isDefault: str = 'N'
    remark: Optional[str] = None


# 通知公告
class NoticeQuery(PageQuery):
    """通知公告查询参数"""
    noticeTitle: Optional[str] = None
    noticeType: Optional[str] = None
    createBy: Optional[str] = None


class NoticeVO(BaseEntity):
    """通知公告视图对象 - 匹配RuoYi sys_notice表结构"""
    noticeId: int
    tenantId: str
    noticeTitle: str
    noticeType: str
    noticeContent: Optional[str] = None
    status: str


class NoticeForm(BaseModel):
    """通知公告表单 - 匹配RuoYi sys_notice表结构"""
    noticeId: Optional[int] = None
    noticeTitle: str
    noticeType: str
    noticeContent: Optional[str] = None
    status: str = '0'
    remark: Optional[str] = None


# 更新前向引用
DeptVO.model_rebuild()
DeptTreeVO.model_rebuild()